package com.gitee.alpha.ie.convert.header;

import com.gitee.alpha.ie.ExcelField;
import com.gitee.alpha.ie.ExcelHelper;
import com.gitee.alpha.ie.convert.HeaderConverter;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.CellData;
import java.util.List;
import java.util.Map;
import org.apache.groovy.util.Maps;

/**
 * 实体数据的导入表头转换<br>
 *
 * @author 冰羽
 * @version 2.2.0
 */
public class EntityHeaderConverter implements HeaderConverter {

  // Entity 导入，默认使用一个Sheet，且在一个Sheet中有一个表格、一个表头

  private Class<?> entityClass;
  private ExcelHelper excelHelper;

  public EntityHeaderConverter(Class<?> entityClass) {
    this(entityClass, new ExcelHelper());
  }

  public EntityHeaderConverter(Class<?> entityClass, ExcelHelper excelHelper) {
    this.entityClass = entityClass;
    this.excelHelper = excelHelper;
  }

  @Override
  public Map<Integer, List<ExcelField>> convert(
      Map<Integer, CellData> headMap, AnalysisContext context) {
    List<ExcelField> excelFields = excelHelper.buildExcelFields(entityClass);

    return Maps.of(0, excelFields);
  }
}
